package com.hhp.hhptt.controller.controllerjinpeng;

import com.hhp.hhptt.common.Result;
import com.hhp.hhptt.entity.Navigation;
import com.hhp.hhptt.entity.SwiperImage;
import com.hhp.hhptt.entity.TeacherXingongyuan;
import com.hhp.hhptt.service.ITeacherService;
import com.hhp.hhptt.utils.commonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/information_engineering")
public class TeacherController {

    @Autowired
    ITeacherService teacherService;
    @GetMapping("/teacher")
    public Result getTeacherInformation() throws MalformedURLException, URISyntaxException, UnsupportedEncodingException {
        //String fileAbsolutePath = commonUtils.getFileAbsolutePathDeep("digtalcampus","teachers","xinxigongchengxueyuan","");
        List<TeacherXingongyuan> list = teacherService.list();
//        for (TeacherXingongyuan teacherXingongyuan : list) {
//            System.out.println(teacherXingongyuan);
//        }

        for (TeacherXingongyuan teacherXingongyuan : list) {
            String image = teacherXingongyuan.getImage();
            String iconUrl = ServletUriComponentsBuilder.fromCurrentContextPath()
                    .path("/images/")
                    .path(image)
                    .toUriString();
            teacherXingongyuan.setImage(iconUrl);
        }

        return Result.success("请求成功，返回信息工程学院教师信息",list);
    }
}
